<?php
/*  
  Copyright (c) 2010-02 SongCMS 
  SongCMS All Rights Reserved. 
  Support:www.SongCMS.com
  QQ:544255858   19951025
  Author:Song  Version:3.17
  Date:2010-08-12 09:28:32
*/
if(!is_numeric($sGET['t']) || !is_numeric($sGET['i'])) MsgBox('1',$Warning[7],'-1'); 
if($sGET['t'] == 1){ 
	$xtype = 'product';
}elseif($sGET['t'] == 2){
	$xtype = 'news';
}elseif($sGET['t'] == 3){
	$xtype = 'survey';
}else{
	$xtype = 'page';	
}
if(!stristr($WebCommentOpen,$xtype)) die($Warning[30]); 
if(!empty($_POST['CommentContent'])){
	$SC -> cache -> clearAll(); 
	$WebCommentOpen = explode(',',$WebCommentOpen);
	if($SYSTEMCONFIG['WebCommentPublication'] == '1' && ($_COOKIE['isLogin'] != 'songcms' || !is_numeric($_COOKIE['User']['ID']))){
		MsgBox('1',$Html['CommentPerm'],'-1');
	} else {
		$cookiename = "COMMENT_{$sGET['t']}_{$sGET['i']}";
		$uid = is_numeric($_COOKIE['User']['ID']) ? $_COOKIE['User']['ID'] : 0;
		if($_COOKIE[$cookiename] != 'songcms'){
			$SQL = "INSERT INTO `{$dbprefix}comment`(`CommentLang`,`CommentType`,`CommentID`,`CommentContent`,`CommentIP`,`CommentUser`,`CommentTime`)";
			$SQL .= "VALUES ('{$Lang}','{$sGET['t']}','{$sGET['i']}','{$_POST['CommentContent']}','{$_SERVER['REMOTE_ADDR']}','{$uid}',NOW());";
			if($sdb -> ExecuteSQL($SQL)){
				@setcookie($cookiename,'songcms');
				MsgBox('1',$Warning[24],'1');
			} else {
				MsgBox('1',$Warning[18],'-1');
			}
		} else {
			MsgBox('1',$Warning[27],'-1');
		}		
	}	
}
switch ($sGET['t']){
	case '0' : $tname = "{$dbprefix}article"; $fname = 'ArticleTitle';	break;
	case '1' : $tname = "{$dbprefix}product"; $fname = 'ProductName';	break;
	case '2' : $tname = "{$dbprefix}news"; $fname = 'NewsTitle';	break;
	case '3' : $tname = "{$dbprefix}survey"; $fname = 'SurveyTitle';	break;
	default: MsgBox('1',$Warning[7],'-1'); break;
}
$SQL = "SELECT `{$fname}` FROM `{$tname}` WHERE `ID` = '{$sGET['i']}'";
if($Title = $sdb->SelectSQL($SQL,0)){
	$Title = $Title[0][0];
} else {
	MsgBox('1',$Warning[8],'-1');
}
$SC -> assign('Title',$Title);
$Total = 10; 
$nColor = '#FF0000'; 
$xColor = '#666666'; 
$Ltext = $Html['page']; 
$SQL = "SELECT a.*,b.`UserName` FROM `{$dbprefix}comment` a LEFT JOIN `{$dbprefix}user` b ON a.`CommentUser` = b.`ID` WHERE a.`CommentType` = '{$sGET['t']}' && a.`CommentID` = '{$sGET['i']}' ";
if($WebCommentShow == 1) $SQL .= "&& a.`CommentAudit` = '1' "; 
$SQL .= "ORDER BY a.`ID` DESC ";
$page = !is_numeric($sGET['p']) ? 1 : $sGET['p']; 
$RsCount = count($sdb->SelectSQL($SQL)); 
$TotalPages = ceil($RsCount / $Total); 
if($TotalPages<1) $TotalPages = 1;
if($page>$TotalPages){$page = $TotalPages;}
@$url = news::url();
$xURL = "./{$url}1"; 
$oURL = './' . $url . ($page-1); 
$sURL = './' . $url . ($page+1); 
$nURL = './' . $url . $TotalPages; 
$pages = "{$Ltext[0]}:<font color=\"{$nColor}\">{$RsCount}</font>&nbsp;|&nbsp; \n";
if($page <= 1){
	$pages .= "<font color=\"{$xColor}\">{$Ltext[1]}</font>&nbsp;|&nbsp; \n";
	$pages .= "<font color=\"{$xColor}\">{$Ltext[2]}</font>&nbsp;|&nbsp; \n";
} else {
	$pages .= "<a href=\"{$xURL}\">{$Ltext[1]}</a>&nbsp;|&nbsp; \n";
	$pages .= "<a href=\"" . $oURL . "\">{$Ltext[2]}</a>&nbsp;|&nbsp; \n";
}
if($page >= $TotalPages){
	$pages .= "<font color=\"{$xColor}\">{$Ltext[3]}</font>&nbsp;|&nbsp; \n";
	$pages .= "<font color=\"{$xColor}\">{$Ltext[4]}</font>&nbsp;|&nbsp; \n";				
} else {
	$pages .= "<a href=\"" . $sURL . "\">{$Ltext[3]}</a>&nbsp;|&nbsp; \n";
	$pages .= "<a href=\"{$nURL}\">{$Ltext[4]}</a>&nbsp;|&nbsp; \n";				
}
$pages .= "<font color=\"{$nColor}\">{$Total}</font>{$Ltext[5]}&nbsp;|&nbsp; \n";
$pages .= '<select name="spage" OnChange="window.open(this.options[this.selectedIndex].value,\'_self\')">' . "\n";
for ($i=1;$i<=$TotalPages;$i++){
	$ipturl = './'.$url.$i;
	if ($i!=$page){
		$pages .= '<option value="' .$ipturl . '">' . str_replace('{&i}',$i,$Ltext[6]) . '</option>' . "\n";
	}else{
		$pages .= '<option selected value="' . $ipturl . '">' . str_replace('{&i}',$i,$Ltext[6]) . '</option>' . "\n";
	}
}
$pages .= '</select>' . "\n";	
$pages .= str_replace('{&TotalPages}',"<font color=\"{$nColor}\">{$TotalPages}</font>",$Ltext[7]) . " \n";
$p[0] = $pages; 
$p[1] = $RsCount; 
$p[2] = $Total; 
$p[3] = $page; 
$p[4] = $TotalPages; 
$p[5] = $xURL; 
$p[6] = $oURL; 
$p[7] = $sURL; 
$p[8] = $nURL; 
$SQL .= "LIMIT " . ($page-1)*$Total . " , " . $Total . " ";
$result = $sdb->SelectSQL($SQL,1);
foreach($result as $i => &$n){
	$n['CommentContent'] = nl2br(htmlspecialchars($n['CommentContent']));	
}
include_once($CodeList . 'top.php');
$SC -> assign('page',$p);
$SC -> assign('comment',$result);
$SC -> display($TemFile,$GetUrlPar);
?>